package com.clcao.mybatis.common.result;

import com.clcao.mybatis.common.constants.enums.ExceptionEnum;

/**
 * @author clcao
 * @since 2025/3/11
 */
public class ResultUtil {
    public static Result<Object> ok() {
        return Result.builder().code(ResultCode.SUCCESS.getCode()).message(ResultCode.SUCCESS.getMessage()).build();
    }

    public static <T> Result<T> ok(T data) {
        return Result.<T>builder().code(ResultCode.SUCCESS.getCode()).message(ResultCode.SUCCESS.getMessage()).data(data).build();
    }

    public static Result<Object> fail() {
        return Result.builder().code(ResultCode.FAIL.getCode()).message(ResultCode.FAIL.getMessage()).build();
    }

    public static Result<Object> fail(String message) {
        return Result.builder().code(ResultCode.FAIL.getCode()).message(message).build();
    }

    public static <T> Result<T> fail(String code, String message) {
        return Result.<T>builder().code(code).message(message).build();
    }

    public static <T> Result<T> fail(ResultCode resultCode) {
        return Result.<T>builder().code(resultCode.getCode()).message(resultCode.getMessage()).build();
    }

    public static <T> Result<T> fail(ExceptionEnum exception) {
        return Result.<T>builder().code(exception.getCode()).message(exception.getMessage()).build();
    }

    public static boolean isSuccess(Result<?> result) {
        return ResultCode.SUCCESS.getCode().equals(result.getCode());
    }
}
